var http=require('http'),fs=require('fs');

http.createServer(function (req, res) {
    var _url=req.url;
    console.log('url:',_url);
    if('GET'==req.method && '/img' == _url.substr(0,4) && '.png'==_url.substr(-4)){//img
        fs.stat(__dirname+_url, function (err, st) {
            if(err || !st.isFile()){
                res.writeHead(404);
                res.end('Not Found');
            }else{
                send(res,__dirname+_url,'application/png');
            }
        });
    }else if('GET'==req.method && '/'==_url){//html
        send(res,__dirname+'/index.html','text/html');
    }else{
        res.writeHead(404);
        res.end('Not Found');
    }
}).listen(3000, function () {
    console.log('My website port 3000');
});

function send(res,_path,type){
    res.writeHead(200,{'content-type':type});
    fs.createReadStream(_path).pipe(res);
}